/*     */ package com.zimbra.cs.index;
/*     */ 
/*     */ import com.google.common.base.Objects;
/*     */ import com.google.common.base.Objects.ToStringHelper;
/*     */ import com.zimbra.common.util.Log;
/*     */ import com.zimbra.common.util.ZimbraLog;
/*     */ import java.io.IOException;
/*     */ import java.io.StringReader;
/*     */ import java.util.ArrayList;
/*     */ import java.util.List;
/*     */ import java.util.Map;
/*     */ import org.apache.lucene.analysis.Analyzer;
/*     */ import org.apache.lucene.analysis.TokenStream;
/*     */ import org.apache.lucene.analysis.tokenattributes.CharTermAttribute;
/*     */ import org.apache.lucene.analysis.tokenattributes.PositionIncrementAttribute;
/*     */ import org.apache.lucene.document.Fieldable;
/*     */ import org.codehaus.jackson.annotate.JsonProperty;
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ public final class TermInfo
/*     */ {
/*     */   @JsonProperty("pos")
/*     */   private List<Integer> positions;
/*     */   
/*     */   void addPosition(int value)
/*     */   {
/*  43 */     if (this.positions == null) {
/*  44 */       this.positions = new ArrayList();
/*     */     }
/*  46 */     this.positions.add(Integer.valueOf(value));
/*     */   }
/*     */   
/*     */   List<Integer> getPositions() {
/*  50 */     return this.positions;
/*     */   }
/*     */   
/*     */   public String toString()
/*     */   {
/*  55 */     return Objects.toStringHelper(this).add("pos", this.positions).toString();
/*     */   }
/*     */   
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */   public static int updateMapWithDetailsForField(Analyzer analyzer, Fieldable field, Map<String, TermInfo> term2info, int pos)
/*     */     throws IOException
/*     */   {
/*  72 */     if (!field.isIndexed()) {
/*  73 */       return pos;
/*     */     }
/*  75 */     Character prefix = (Character)LuceneFields.FIELD2PREFIX.get(field.name());
/*  76 */     if (prefix == null) {
/*  77 */       ZimbraLog.index.info("TermInfo.updateMapWithDetailsForField - skipping indexed field " + field.name() + " isTokenized=" + field.isTokenized());
/*     */       
/*  79 */       return pos;
/*     */     }
/*  81 */     if (field.isTokenized()) {
/*  82 */       TokenStream stream = field.tokenStreamValue();
/*  83 */       if (stream == null) {
/*  84 */         stream = analyzer.tokenStream(field.name(), new StringReader(field.stringValue()));
/*     */       }
/*  86 */       CharTermAttribute termAttr = (CharTermAttribute)stream.addAttribute(CharTermAttribute.class);
/*  87 */       PositionIncrementAttribute posAttr = (PositionIncrementAttribute)stream.addAttribute(PositionIncrementAttribute.class);
/*  88 */       stream.reset();
/*  89 */       while (stream.incrementToken()) {
/*  90 */         if (termAttr.length() != 0)
/*     */         {
/*     */ 
/*  93 */           String term = prefix + termAttr.toString();
/*  94 */           TermInfo info = (TermInfo)term2info.get(term);
/*  95 */           if (info == null) {
/*  96 */             info = new TermInfo();
/*  97 */             term2info.put(term, info);
/*     */           }
/*  99 */           pos += posAttr.getPositionIncrement();
/* 100 */           info.addPosition(pos);
/*     */         }
/*     */       }
/*     */     }
/*     */     else {
/* 105 */       String term = prefix + field.stringValue();
/* 106 */       TermInfo info = (TermInfo)term2info.get(term);
/* 107 */       if (info == null) {
/* 108 */         info = new TermInfo();
/* 109 */         term2info.put(term, info);
/*     */       }
/*     */     }
/* 112 */     return pos;
/*     */   }
/*     */ }


/* Location:              /home/mint/zimbrastore.jar!/com/zimbra/cs/index/TermInfo.class
 * Java compiler version: 7 (51.0)
 * JD-Core Version:       0.7.1
 */